/*
 * Parser.h
 *
 *  Created on: Apr 13, 2012
 *      Author: marc
 */

#ifndef PARSER_H_
#define PARSER_H_

#include <list>
#include <iostream>
#include "Token.h"

using namespace std;

class Parser {
private:
	list<Token*>* tokens;
	list<Token*>::iterator iter;
	int fd[2];
	int pipeIn;
	int pipeOut;
	int nextIn;
	list<Token*>* cmd;
	bool parseLine();
	bool parseCommands();
	bool parseOptionalCommands();
	bool parseCommand();
	bool parseRemains();
	bool parseArgument();
	bool parseInputOutput();
	bool parseFilename();
	bool expect(int);

	void execute();
	void preparePipe();

	bool input, output, append;
	string fileIn;
	string fileOut;

public:
	Parser();
	virtual ~Parser();
	bool parse(list<Token*>*);
};

#endif /* PARSER_H_ */
